﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using AMatysiak.Reflection;

namespace AMatysiakTest.Reflection
{
    [TestClass]
    public class ReflectionSerializerTest
    {
        private class SomeClass : ReflectionSerializer
        {
            public int A { get; set; }
            public string B { get; set; }
        }

        [TestMethod]
        public void serialize()
        {
            SomeClass sc = new SomeClass() { A = 3, B = "Test" };

            string serial = sc.Serialize();

            Assert.AreEqual("A=3;B=Test;", serial);
        }

        [TestMethod]
        public void serializeWhenOnePropertyIsEmpty()
        {
            SomeClass sc = new SomeClass() { A = 3 };

            string serial = sc.Serialize();

            Assert.AreEqual("A=3;B=;", serial);
        }

        [TestMethod]
        public void deserialize()
        {
            string serial = "A=3;B=Test";

            SomeClass sc = new SomeClass();
            sc.Deserialize(serial);

            Assert.AreEqual(3, sc.A);
            Assert.AreEqual("Test", sc.B);
        }

        [TestMethod]
        public void deserializeWhenOnePropertyIsEmpty()
        {
            string serial = "A=3;B=";

            SomeClass sc = new SomeClass();
            sc.Deserialize(serial);

            Assert.AreEqual(3, sc.A);
            Assert.AreEqual("", sc.B);
        }

        [TestMethod]
        [ExpectedException(typeof(NullReferenceException))]
        public void deserializeWhenOnePropertyNotExist()
        {
            string serial = "A=3;C=";

            SomeClass sc = new SomeClass();
            sc.Deserialize(serial);
        }
    }
}
